#include <bits/stdc++.h>
using namespace std;
int KMPStrMatching(string T,string P,int *N,int start)
{
    int j = 0;
    int i = start;
    int pLen = P.length();
    int tLen = T.length();
    if(tLen-start<pLen)
    {
        return -1;
    }
    while(j<pLen&&i<tLen)
    {
        if(j == -1||T[i] == P[j])
        {
            i++;
            j++;
        }
        else
            j = N[j];
    }
    if(j>=pLen)
        return (i-pLen);
    else
        return -1;
}
int * findNext(string P)
{
    int j,k;
    int m = P.length();
    int *next = new int[m];
    next[0] = -1;
    j = 0;k = -1;
    int temp;
    while(j<m-1)
    {
        while(k>=0&&P[k]!=P[j])
            k = next[k];
        j++;
        k++;
        next[j] = k;
    }
    return next;
}
int main() {
    int N,M;
    cin>>N>>M;
    vector<string> S_str;
    vector<string> P_str;
    //存储String
    for(int i=0;i<N;i++)
    {
        string temp;
        cin>>temp;
        S_str.push_back(temp);

    }
    //存储patter
    for(int i=0;i<M;i++)
    {
        string temp;
        cin>>temp;
        P_str.push_back(temp);
    }
    // 存储结果
    vector<int> result;
    for(auto i:P_str)
    {
        int count=0;
        for(auto j:S_str)
        {
            int *n = findNext(i);
            int r = KMPStrMatching(j,i,n,0);
            if(r>0)
                count++;
        }
        result.push_back(count);
    }
    for(auto i:result)
        cout<<i<<"\n";
    return 0;
}
